<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const arr = [9,2,7,6,4,3,5]

        // map的作用是数据处理之后返回一个新的数组
        // 如果回调函数没有return，则新数组里面的每一项都是undefined

        // const newArr = arr.map((item,index) => {
        //     return item
        // })
        // console.log(newArr)

        Array.prototype.myMap = function (fn) {
            let newArr = []
            for (let i=0;i<this.length;i++) {
                newArr.push(fn(this[i],i,this)) 
            }
            return newArr
        }

        const a = arr.myMap(item => {
            return item+1
        })
        console.log(a)
    </script>
</body>
</html>